package collection.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class StreamApiDemo {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Random random = new Random();
        for(int i = 0; i < 10; i++) {
            list.add(random.nextInt(10));
        }

        System.out.println(list);

        List<Integer> list2 = list.stream()
                                  .map( a -> a*3 )
                                  .collect(Collectors.toList());
        System.out.println(list2);

        List<Integer> list3 = list.stream()
                                  .filter(a -> a%2 != 0)
                                  .collect(Collectors.toList());
        System.out.println(list3);

        List<Integer> list4 = list.stream()
                                  .distinct()
                                  .collect(Collectors.toList());
        System.out.println(list4);

        List<Integer> list5 = list.stream()
                                  .sorted((a,b) -> b-a)
                                  .collect(Collectors.toList());
        System.out.println(list5);

        List<Integer> list6 = list.stream()
                                  .map(a -> a*3 )
                                  .filter( a -> a % 2 != 0).distinct()
                                  .sorted( ( a , b ) -> b - a )
                                  .collect(Collectors.toList());
        System.out.println(list6);
    }
}
